<script setup>
import { ref, computed } from "vue";
import { formatCount } from "@/utils/format.js";

const props = defineProps({
  detail: {
    type: Object,
  },
});

const backGround = computed(() => ({
  position: "relative",
  height: "400rpx",
  "background-image": 'url("' + props.detail?.coverImgUrl + '")',
  "background-position": "center",
  "background-size": "cover",
  "background-repeat": "no-repeat",
  filter: "blur(40px)",
}));

const popup = ref(null);
const openPopup = () => {
  popup.value.open("center");
};
</script>

<template>
  <view class="music-list-detail" v-if="props.detail">
    <view :style="backGround"></view>
    <view class="contetn-wrap">
      <view class="list-info">
        <image
          class="list-img"
          :src="props.detail.coverImgUrl + '?param=200y200'"
          mode="scaleToFill"
        />
        <view class="list-info-wrap">
          <view class="music-list-title">{{ props.detail.name }}</view>
          <view class="creator-info">
            <image
              class="creator-img"
              :src="props.detail.creator.avatarUrl + '?param=200y200'"
              mode="scaleToFill"
            />
            <text class="nickname">{{ props.detail.creator.nickname }}</text>
          </view>
          <view class="count">
            <text class="track-count">歌曲：{{ props.detail.trackCount }}</text>
            <text>播放：{{ formatCount(props.detail.playCount) }}</text>
          </view>
        </view>
      </view>
      <view class="music-des">
        <view class="description" @tap="openPopup">
          {{ props.detail.description }}
        </view>
        <view class="more">
          <i class="iconfont icon-gengduo1"></i>
        </view>
      </view>
      <view class="button-wrap">
        <view class="button">
          <i class="iconfont icon-fenxiang"></i>
          <text>{{ formatCount(props.detail.shareCount) }}</text>
        </view>
        <view class="button">
          <i class="iconfont icon-liaotian"></i>
          <text>{{ formatCount(props.detail.commentCount) }}</text>
        </view>
        <view class="button">
          <i class="iconfont icon-shoucang"></i>
          <text>{{ formatCount(props.detail.subscribedCount) }}</text>
        </view>
      </view>
    </view>
    <!-- 弹出层：歌单描述 -->
    <uni-popup ref="popup" type="center" class="popup-wrap">
      <view class="popup-content-wrap">
        <image
          :src="props.detail?.coverImgUrl + '?param=200y200'"
          class="popup-list-img"
          mode="scaleToFill"
        />
        <view class="popup-title">{{ props.detail.name }}</view>
        <scroll-view class="popup-description">
          {{ props.detail.description }}
        </scroll-view>
      </view>
    </uni-popup>
    <!-- / 弹出层：歌单描述 -->
  </view>
</template>

<style lang="scss">
.music-list-detail {
  position: relative;
  font-size: 28rpx;

  .contetn-wrap {
    position: absolute;
    top: 0;
    height: 400rpx;
    padding: 20rpx 30rpx 0 30rpx;
    background-color: rgba(255,255,255,0.2);
    border-radius: 0 0 20rpx 20rpx;
    .list-info {
      display: flex;
      .list-img {
        width: 200rpx;
        height: 200rpx;
        border-radius: 16rpx;
        background-color: #ddd;
      }
      .list-info-wrap {
        margin-left: 20rpx;
        display: flex;
        flex-direction: column;
        justify-content: space-around;
        .music-list-title {
          font-size: 30rpx;
          font-weight: bold;
          width: 470rpx;
          display: -webkit-box;
          -webkit-line-clamp: 2;
          -webkit-box-orient: vertical;
          overflow: hidden;
          text-overflow: ellipsis;
        }
        .creator-info {
          display: flex;
          align-items: center;
          .creator-img {
            border-radius: 50%;
            height: 50rpx;
            width: 50rpx;
          }
          .nickname {
            margin-left: 10rpx;
          }
        }
        .count {
          font-size: 26rpx;
          .track-count {
            margin-right: 20rpx;
          }
        }
      }
    }
    .music-des {
      margin: 30rpx 0;
      position: relative;
      width: 670rpx;
      font-size: 26rpx;
      .description {
        overflow: hidden;
        height: 38rpx;
      }
      .more {
        position: absolute;
        height: 30rpx;
        top: 0;
        right: -30rpx;
      }
    }
    .button-wrap {
      display: flex;
      justify-content: space-around;
      .button {
        display: flex;
        align-items: center;
        justify-content: center;
        height: 70rpx;
        width: 90px;
        background-color: rgba(240, 240, 240, 0.5);
        border-radius: 40rpx;
        font-size: 24rpx;
        font-weight: bold;
        color: #444;
        .iconfont {
          margin-right: 10rpx;
          font-size: 42rpx;
        }
      }
    }
  }

  .popup-wrap {
    position: relative;
    .popup-content-wrap {
      padding: 0 50rpx;
      color: #fff;
      display: flex;
      flex-direction: column;
      align-items: center;
      .popup-list-img {
        height: 400rpx;
        width: 400rpx;
        border-radius: 20rpx;
      }
      .popup-title {
        margin-bottom: 20rpx;
        line-height: 100rpx;
        font-weight: bold;
      }
      .popup-description {
        white-space: pre-wrap;
        font-size: 24rpx;
      }
    }
  }
}
</style>
